#include "DialogCoef.h"
#include <stdlib.h>
#include "cv.h"

DialogCoef::DialogCoef( wxWindow* parent )
:
DialogCoefTemplate( parent )
{
	char* value = new char[30];
	wxString wxValue;
	
		
	MainFrame* mainWindow = (MainFrame*) parent;
	
	CvScalar low = mainWindow->getLowCoef();
	
	sprintf(value, "%f", low.val[0]);
	wxValue = wxValue.FromAscii(value);
	textCtrlLCoef0->SetValue(wxValue);
	
	sprintf(value, "%f", low.val[1]);
	wxValue = wxValue.FromAscii(value);
	textCtrlLCoef1->SetValue(wxValue);
	
	sprintf(value, "%f", low.val[2]);
	wxValue = wxValue.FromAscii(value);
	textCtrlLCoef2->SetValue(wxValue);
	
	//High Values
	CvScalar high = mainWindow->getHighCoef();
	
	sprintf(value, "%f", high.val[0]);
	wxValue = wxValue.FromAscii(value);
	textCtrlHCoef0->SetValue(wxValue);
	
	sprintf(value, "%f", high.val[1]);
	wxValue = wxValue.FromAscii(value);
	textCtrlHCoef1->SetValue(wxValue);
	
	sprintf(value, "%f", high.val[2]);
	wxValue = wxValue.FromAscii(value);
	textCtrlHCoef2->SetValue(wxValue);
	
	this->ShowModal();
	delete value;
	
}


void DialogCoef::OnOkClick( wxCommandEvent& event )
{
	MainFrame* parent = (MainFrame*)this->GetParent();
	
	double lCoef0;
	double lCoef1;
	double lCoef2;
	
	double hCoef0;
	double hCoef1;
	double hCoef2;
	
	wxString value;
	value = textCtrlLCoef0->GetValue();
	lCoef0 = atof(value.char_str());
	
	value = textCtrlLCoef1->GetValue();
	lCoef1 = atof(value.char_str());
	
	value = textCtrlLCoef2->GetValue();
	lCoef2 = atof(value.char_str());
	
	
	value = textCtrlHCoef0->GetValue();
	hCoef0 = atof(value.char_str());
	
	value = textCtrlHCoef1->GetValue();
	hCoef1 = atof(value.char_str());
	
	value = textCtrlHCoef2->GetValue();
	hCoef2 = atof(value.char_str());
	
		
	parent->setLowCoef(cvScalar(lCoef0,lCoef1,lCoef2));
	parent->setHighCoef(cvScalar(hCoef0,hCoef1,hCoef2));
	
	
	this->EndModal(1);
}


